package com.ylzinfo.ms.factory;


import com.ylzinfo.ms.factory.baseHandle.AESBaseHandle;
import com.ylzinfo.ms.factory.baseHandle.RSABaseHandle;

/**
 * @Description: 定义加解密的工厂类
 * @Product: IntelliJ IDEA
 * @Author Rogchen rogchen128@gmail.com
 * @Created Date: 2019/3/29 10:35
 **/
public class EnAndDeSampleFactory {

    /**
     * @Description 通过入参反射
     * @Author Rogchen
     * @Date 10:13 2018/12/7
     * @Param cs class
     * @Return void
     **/
    public static AbstoryEnAndDeFactory getClass(Class<?> cs) {
        AbstoryEnAndDeFactory h = null;
        try {
            h = (AbstoryEnAndDeFactory) Class.forName(cs.getName()).newInstance();
        } catch (InstantiationException e) {
            e.printStackTrace();
            System.out.println("实例化errer");
        } catch (IllegalAccessException e) {
            e.printStackTrace();
            System.out.println("get error");
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
            System.out.println("case error");
        }
        return h;
    }

    /**
     * @Description 通过参数类型来进行获取实例，目前只提供aes和rsa加解密
     * @Author Rogchen
     * @Date 13:56 2019/3/29
     * @Param [type]
     * @Return com.ylzinfo.common.factory.AbstoryEnAndDeFactory
     **/
    //todo 写死的switch
    public static AbstoryEnAndDeFactory switchByType(String type) {
        AbstoryEnAndDeFactory factory = null;
        switch (type.toLowerCase()) {
            case Constants.AES:
                factory = new AESBaseHandle();
                break;
            case Constants.RSA:
                factory = new RSABaseHandle();
                break;
            default:
                factory = new AESBaseHandle();
                break;
        }
        return factory;
    }
}
